package com.zplus.managers.petservices;


import com.zplus.managers.petservices.entities.Pet;
import com.zplus.managers.petservices.mappers.PetMapper;
import com.zplus.managers.petservices.services.PetState;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.List;

@SpringBootTest
public class PetMapperDemos
{
    @Autowired
    PetMapper petMapper;
    @DisplayName("测试PetMapperAPI")
    @Test
    public void testPetMapper()
    {
        List<Pet> pets = petMapper.queryAllPetByState(PetState.UNADOPTED.ordinal());
        // success if size equal to 3
        // NOTE: equaltion should be updated once table 'pet' got updated.
        assertEquals(pets.size(), 3);
    }
    @DisplayName("测试非法查询")
    @Test
    public void testInvalidQuery()
    {
        int id = 4999;
        Pet pet = petMapper.queryPetById(id);
        assertNull(pet);
    }

    @Test
    public void testChangePetInfo()
    {
        Pet pet = petMapper.queryPetById(1);
        pet.setBirthday("2023-07-31");
        int i = petMapper.updatePetInfo(pet);
        System.out.println( i > 0);

    }
}
